package day09_charset_io.com.itheima.d3_finally;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test3 {
    public static void main(String[] args) {
        try (
                FileInputStream is = new FileInputStream("d:/a.txt");
                FileOutputStream os = new FileOutputStream("d:/b.txt");
                MyConnection conn = new MyConnection("连接1");
        ) {
            byte[] buffer = new byte[1024];
            int len;
            while ((len = is.read(buffer)) != -1){
                os.write(buffer, 0, len);
            }
            System.out.println("复制完毕！");
            os.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

class MyConnection implements AutoCloseable {
    private String name;

    public MyConnection(String name) {
        this.name = name;
    }

    @Override
    public void close() throws Exception {
        System.out.println("关闭连接：" + name);
    }
}
